package edu.progra2.ventas.action;

import org.apache.struts2.convention.annotation.*;
import javax.persistence.*;

import edu.progra2.common.util.Utilitario;
import edu.progra2.ventas.model.*;

@Action(value="remove-cliente-*",
params={"dni","{1}"},
results={@Result(name="exito", 
location="/message.jsp")
} )
public class RemoveClienteAction {
	private Long dni;
	private String message;
	
	public String execute(){
		String result="exito";
		setMessage("El empleado ha sido eliminado correctamente");
		EntityManager em=
		   Utilitario.getInstance().getEntityManager();
		EntityTransaction tx=em.getTransaction();
		try{
			tx.begin();
			Cliente clientes=em.find(Cliente.class, dni);
			em.remove(clientes);
			tx.commit();
		}catch(Exception ex){
			ex.printStackTrace();
			tx.rollback();
			setMessage("El empleado no se ha eliminado correctamente");
		}		
		return result;
	}

	

	public Long getDni() {
		return dni;
	}



	public void setDni(Long dni) {
		this.dni = dni;
	}



	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	
}
